﻿<template>
    <el-dialog :title="titleMap[mode]" v-model="visible" :width="1200" destroy-on-close>
        <el-form
            :model="entityObj"
            :rules="rules"
            :disabled="mode == 'Show'"
            ref="dialogForm"
            label-width="100px"
        >
            <el-row>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="赠送编号:">{{entityObj.giveOrderCode}}</el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="赠送单位:">{{entityObj.purchaseUnityName}}</el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="要货单位:">
                        <el-tooltip placement="top">
                            <template #content>
                                联系人: {{entityObj.realName}}
                                <br />
                                联系电话:{{entityObj.mobile}}
                                <br />
                                收货地址:{{entityObj.address}}
                            </template>
                            <span style="color: blue;">{{entityObj.storeName}}</span>
                        </el-tooltip>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="要货编号:">{{entityObj.applyOrderId>0? entityObj.applyOrderCode:"无"}}</el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="要货时间:">{{entityObj.applyOrderId>0? entityObj.applyDate:"无"}}</el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="期望到货时间:">{{entityObj.applyOrderId>0? entityObj.expectedDate:"无"}}</el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="赠送人:">{{entityObj.giveName}}</el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="赠送时间:">{{entityObj.giveDate}}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="8">
                    <el-form-item label-width="120px" label="备注:">{{entityObj.remarks}}</el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label-width="120px" label="赠送清单:">
                        <el-table
                            :data="entityObj.giveOrderItems"
                            :border="true"
                            style="width: 100%"
                            :row-class-name="setRowClass"
                        >
                            <el-table-column label="物料编码" prop="materialCode" min-width="120"/>
                            <el-table-column label="物料名称" prop="materialName" min-width="140"/>
                            <!-- <el-table-column label="分类" prop="materialTypeName" min-width="120"/> -->
                            <el-table-column label="规格" prop="materialSpecs" min-width="130"/>
                            <el-table-column label="单位" prop="unitName" min-width="100"/>
                            <el-table-column label="赠送数量" prop="qty" min-width="100"/>
                            <el-table-column label="配送单价" prop="price" min-width="100"/>
                            <el-table-column label="金额" prop="totalAmount" min-width="100"/>
                            <el-table-column label="采购模式" v-if="orgType==1" prop="purchaseSaleTypeDesc" min-width="120"/>
                            <el-table-column label="供应商"  v-if="orgType==1" prop="supplierName" min-width="140"/>
                            <el-table-column label="备注" prop="remarks" min-width="160"/>
                        </el-table>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </el-dialog>
</template>

<script>
import tool from "@/utils/tool";
export default {
    emits: ["success", "closed"],
    data() {
        return {
            tableRowClassName: "warning-row",
            tableRowClassName1: "success-row",
            mode: "Add",
            titleMap: {
                Add: "新增",
                Edit: "编辑",
                Show: "查看",
            },
            entityObj: {
            },
            materialState: false,
            queryList: {},
            visible: false,
            isSaveing: false,
            needSaveFlag: false,
            orgType:2,
            props: {
                label: "supplierName",
                value: "supplierId",
            },
            materialProps: {
                label: "materialCode",
                value: "materialId",
                items: "materialItems",
            },
            materialTypeTree: [],
            optionsBrand: [],
            optionsUnit: [],
            optionsPurchaseSaleType: [],
            suppliers: [],
        };
    },
    computed: {},
    methods: {
        handleBeforeClose() {
            this.$confirm("信息未保存,确定要关闭吗？", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    this.visible = false;
                })
                .catch(() => {
                    // 用户点击了取消按钮，不执行关闭
                });
        },
        //显示=
        open(mode = "Add") {
            this.mode = mode;
            this.visible = true;
            return this;
        },
        //表单注入数据
        async setData(data) {
            try {
                var returnValue = await this.$API.auth.GetProcessApi.get(
                    `give-order/${data.giveOrderId}`,
                    {}
                );
                if (returnValue.status == 200) {
                    this.entityObj = { ...returnValue.response};
                } else {
                    this.$message.error("操作失败:" + returnValue.msg);
                }
            } catch (error) {
                this.loading = false;
                return false;
            }
        },
        async initOptions() {
            
        },
        setRowClass({ row }) {
            console.log(row.status)
            //终止
            if (row.status == 9) {
                return "selected-row-color-grey";
            }
            return "";
        },
    },
    async mounted() {
        //this.entityObj.purchaseUnityName = tool.data.get("USER_INFO").OrgName;
        //this.entityObj.crName = tool.data.get("USER_INFO").Name;
        //this.entityObj.crDate = tool.formatDate(new Date());
        this.orgType = tool.data.get("USER_INFO").AccountType;
        await this.initOptions();
    },
};
</script>

<style scoped>
.el-table .warning-row {
    --el-table-tr-bg-color: var(--el-color-warning-light-9);
}
.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-light-9);
}
.el-form-item {
    margin-bottom: 8px !important;
}

.el-table .selected-row-color-grey {
    color: #000000 !important;
    text-decoration: line-through; /* 删除线 */
}
</style>
